home *** CD-ROM | disk | FTP | other *** search
- /*****************************************************************************
- MODULE: rbget.c
- PURPOSE: recio character delimited integral number input functions
- COPYRIGHT: (C) 1994 William Pierpoint
- COMPILER: Borland C Version 3.1
- OS: MSDOS Version 6.2
- VERSION: 2.00
- RELEASE: April 15, 1994
- *****************************************************************************/
-
- #include <ctype.h>
- #include <errno.h>
- #include <limits.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
-
- #include "_rbget.h"
-
- /****************************************************************************/
- unsigned long /* return unsigned long */
- str2ul( /* convert string to unsigned long */
- const char *nptr, /* pointer to string to convert */
- char **endptr, /* pointer to conversion leftover string */
- int base) /* base (radix) of number */
- /****************************************************************************/
- /* note: unlike strtoul, str2ul tests for a negative number */
- {
- unsigned long ul=0UL; /* result to return */
- const char *np=nptr; /* pointer to string */
-
- errno = 0;
-
- /* skip over white space */
- while (isspace(*np)) np++;
-
- /* if first non-white space is a minus sign */
- if (*np == '-') {
-
- /* position endptr at the minus sign */
- if (endptr) *endptr = (char *) np;
-
- } else {
-
- ul = strtoul(nptr, endptr, base);
-
- }
- return (ul);
- }
-
- /****************************************************************************/
- /* rbget_fn() - define rbget functions */
- /****************************************************************************/
- #define uint unsigned int
- #define ulong unsigned long
- #ifdef __BORLANDC__
- #pragma warn -ccc
- #endif
-
- rbget_fn( int, rbgeti, 0, long, strtol, INT_MIN, INT_MAX)
- rbget_fn( uint, rbgetui, 0, ulong, str2ul, 0, UINT_MAX)
- rbget_fn( long, rbgetl, 0L, long, strtol, LONG_MIN, LONG_MAX)
- rbget_fn( ulong, rbgetul, 0L, ulong, str2ul, 0, ULONG_MAX)
-